﻿using System;
using System.IO;
using MoreShaperRTD;
using System.Collections.Generic;
namespace hk_ztd2pwv
{
    class Program
    {
        static void Main(string[] args)
        {
            string dirname = @"F:\data\ChongQing\hksc";
            string outdir = @"F:\data\ChongQing\pwv";
            
            DirectoryInfo directoryInfo = new DirectoryInfo(dirname);

            List<string> listStrTime = new List<string>() { "00:00:00.00", "12:00:00.00" };

            Coordinate3D coor = new Coordinate3D(-2414267.4186, 5386768.7781, 2407459.8368);
            CoordinateGeo coorGeo = coor.ToGeo();
            string station = "HKSC";
            foreach(FileInfo fileInfo in directoryInfo.GetFiles())
            {
                string filename = fileInfo.FullName;
                ReadZTD stationZTD = new ReadZTD(filename);
                foreach(string strTime in listStrTime)
                {


                    EpochZTD epochZTD0 = stationZTD.GetZTDNearst(strTime);
                    int doy = epochZTD0.epochTime.ToDoy();
                    int hour = Convert.ToInt16(strTime.Substring(0, 2));
                    int minute = 0;

                    string outfn = string.Format("2018{0,0:D3}{1,0:D2}{2,0:D2}.Aresztd", doy, hour, minute);
                    string outfile = Path.Combine(outdir, outfn);
                    string strlat = coorGeo.GetLatDMS();
                    string strlon = coorGeo.GetLonDMS();
                    string line = string.Format("{0}   {1}  {2}        {3,9:F4}  {4,9:F4}", station, strlat, strlon, coorGeo.hgt, epochZTD0.ztd);

                    List<string> listOutline = new List<string>();
                    listOutline.Add("Site    latitude(d'\")   longitude(d'\")        height(m)   ztd(m)");
                    listOutline.Add(line);
                    // epochZTD0.Print();
                    File.WriteAllLines(outfile, listOutline);
                }

            }
        }


    }
}
